package algotithm.interview.神策数据test.test4;

/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/5-23:02
 * 斐波拉契数列第N项
 */
public class Solution {

    public static void main(String[] args) {
        int n = 5;
        Solution solution = new Solution();
        int fib = solution.fib(n);
        System.out.println(fib);
    }

    public int fib(int n) {
        int a = 0, b = 1;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum = a + b;
            a = b;
            b = sum;
        }
        return a;
//        int[] dp = new int[n+1];
//        dp[0] = 0;
//        dp[1] = 1;
//        for (int i = 2; i <= n; i++) {
//            dp[i] = dp[i-1] + dp[i-2];
//        }
//        return dp[n];
    }

}
